import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout'
const routes = [
  {
    path: '/login',
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/login/callback',
    component: () => import('@/views/login/callback.vue')
  },
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/home/index.vue')
      },
      {
        path: '/category/:id', //  /home/sub
        component: () => import('@/views/category/index.vue')
      },
      {
        path: '/category/sub/:id',
        props: true,
        component: () => import('@/views/category/sub.vue')
      },
      {
        path: '/product/:id',
        component: () => import('@/views/product/index.vue')
      }
    ]
  }
]

const router = createRouter({
  // vue2.x:mode:'history/hash'   vue3.x   history:createWebHashHistory()/createWebHistory()
  history: createWebHashHistory(),
  routes,
  scrollBehavior () {
    // 2.x版本用法： return { x: 0, y: 0 }
    return { left: 0, top: 0 }
  }
})
// router.afterEach(() => {
//   window.scrollTo(0, 0)
// })

export default router
